package cn.miaoyao.miaoyaoms.controller;


import cn.miaoyao.miaoyaoms.entity.Notice;
import cn.miaoyao.miaoyaoms.entity.User;
import cn.miaoyao.miaoyaoms.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sun
 * @since 2023-05-13
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    /**
     * 添加公告信息
     * @param notice
     * @return
     */
    @PostMapping("/addNotice")
    public Boolean addNotice(Notice notice, HttpServletRequest request) {
        if (!ObjectUtils.isEmpty(notice)) {
            User user = (User) request.getSession().getAttribute("user");
            notice.setUid(user.getUid());//添加用户id
            notice.setNoticetime(new Date());//设置公告发布的时间
            boolean save = noticeService.save(notice);
            return save;
        }
        return false;
    }
}

